package TankCampaignGame.com.sjw.Game;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class BulletThread extends Thread{
    Bullet bullet = null;
    public BulletThread(Bullet bullet){
        this.bullet = bullet;
    }
    public void run(){
        while (true){
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            switch (bullet.getDirect()){
                case 0:
                    int y = bullet.getY();
                    y -= bullet.getSpeed();
                    bullet.setY(y);
                    break;
                case 1:
                    int x = bullet.getX();
                    x += bullet.getSpeed();
                    bullet.setX(x);
                    break;
                case 2:
                    int y1 = bullet.getY();
                    y1 += bullet.getSpeed();
                    bullet.setY(y1);
                    break;
                case 3:
                    int x1 = bullet.getY();
                    x1 -= bullet.getSpeed();
                    bullet.setY(x1);
                    break;
            }
            System.out.println(bullet.getX()+" "+bullet.getY());
            if(bullet.getY() <= 0 || bullet.getX() <=0 || bullet.getX() >= 1000 || bullet.getY() >= 1000){
                bullet.setLive(false);
                break;
            }
        }
    }
}
